package ac.neec.mio.ui.fragment;

import ac.neec.data.SpecificActivities;
import ac.neec.listener.DialogFragmentCallback;
import ac.neec.mio.R;
import ac.neec.mio.ui.adapter.TypeSelectorAdapter;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.View;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
/**
 * Created by kobayashi on 2014/01/25.
 */

public class TypeSelectorFragment extends DialogFragment {
    private ExpandableListView typeListView;
    private DialogFragmentCallback<SpecificActivities> mDialogCallBack;
    private BaseExpandableListAdapter adapter;
    private ExpandableListView.OnChildClickListener mOnChildClickListener =
            new ExpandableListView.OnChildClickListener() {
                @Override
                public boolean onChildClick( ExpandableListView parent, View v, int groupPosition, int childPosition, long id ) {
                    return false;
                }
            };

    @Override
    public void onCreate( Bundle savedStateInstance ) {
        super.onCreate( savedStateInstance );
//        setStyle(DialogFragment.STYLE_NORMAL, R.style.Theme_MyDialog);
    }

    @Override
    public Dialog onCreateDialog( Bundle savedInstanceState ) {
        Dialog dialog = super.onCreateDialog( savedInstanceState );
        View view = getActivity().getLayoutInflater().inflate( R.layout.dialog_type_selector, null );

        Bundle bundle = getArguments();
        if ( bundle != null )
            mDialogCallBack = (DialogFragmentCallback) bundle.getSerializable("callback" );

        typeListView = (ExpandableListView) view.findViewById( R.id.dialog_type_selector_listview );
        adapter = new TypeSelectorAdapter( getActivity() );
        typeListView.setAdapter( adapter );
        typeListView.setOnChildClickListener( new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick( ExpandableListView parent, View v, int groupPosition, int childPosition, long id ) {
                SpecificActivities item = (SpecificActivities)adapter.getChild( groupPosition, childPosition );
                mDialogCallBack.callbackData( item );
                dismiss();
                return false;
            }
        } );

        dialog.setContentView( view );
        return dialog;
    }
}
